package com.example.demo.anothor;

import com.example.demo.model.ArticleInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ArticleMapper {

    @Results(value = {//最好将映射关系写全
            @Result(column = "id", property = "id"),
            @Result(column = "title", property = "title"),
            @Result(column = "content", property = "content"),
            @Result(column = "uid", property = "uid"),
            @Result(column = "delete_flag",property = "deleteFlag"),
            @Result(column = "create_time",property = "createTime"),
            @Result(column = "update_time",property = "updateTime")
    })
    @Select("SELECT ta.id,ta.title,ta.content,ta.uid,tb.username,tb.age,tb.gender,tb.create_time " +
            "FROM article_info ta LEFT JOIN user_info tb ON ta.uid = tb.id WHERE ta.id = #{id}")
    ArticleInfo selectById(Integer id);

    @Select("select * from article_info")
    List<ArticleInfo> selectAll();
}
